from time import sleep

from selenium import webdriver


def open_browser(browser):
    try:
        driver = getattr(webdriver, browser)()
    except Exception as e:
        print(e)
        driver = webdriver.Chrome()
    return driver


class Key:
    def __init__(self, browser):
        # self.driver = webdriver.Chrome()
        self.driver = open_browser(browser)

    def open(self, url):
        self.driver.get(url)

    def locate(self,name,value):
        return self.driver.find_element(name,value)

    def input(self,name,value,inputdata):
        self.locate(name,value).send_keys(inputdata)

    def click(self,name,value):
        self.locate(name,value).click()

    def sleep(self,time_):
        sleep(int(time_))

    def quit(self):
        self.driver.quit()